#pragma once
#include <string>

std::string add(const std::string& a, const std::string& b) {
	std::string res;

	std::string::const_reverse_iterator ItA = a.rbegin();
	std::string::const_reverse_iterator ItB = b.rbegin();

	char ca, cb;
	bool over = false;
	for( ; ItA != a.rend() && ItB != b.rend(); ++ItA, ++ItB ){
		ca = *ItA + over;
		cb = *ItB;
		over = ca - 48 + cb - 48 > 9;
		res.insert(res.begin(), ca - 48 + cb - (over ? 10 : 0));
	}

	for( ; ItA != a.rend(); ++ItA ){
		ca = *ItA + over;
		over = ca - 48 > 9;
		res.insert(res.begin(), ca - (over ? 10 : 0));
	}
	for( ; ItB != b.rend(); ++ItB ){
		cb = *ItB + over;
		over = cb - 48 > 9;
		res.insert(res.begin(), cb - (over ? 10 : 0));
	}

	if( over )
		res.insert(res.begin(), '1');

	return res;
}


